/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MViewFrame.java
 *
 * Created on 01.04.2010, 21:22:43
 */
package de.jmda.mview;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.lang.model.element.TypeElement;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

import de.jmda.mview.typeshape.DisplayOptionsModelContainer;
import de.jmda.mview.typeshape.TypeShape;
import de.jmda.util.gui.awt.graphics.IconProvider;

/**
 *
 */
public class MViewFrame extends JFrame
{
  private static final long serialVersionUID = 1L;

  private static DisplayOptionsModelContainer displayOptionsModelContainer =
			new DisplayOptionsModelContainer();
	
	public MViewFrame(String string)
	{
		super(string);
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents()
  {
    desktopPane = new DesktopPane(getClass().getSimpleName());

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;

    JScrollPane scrollPane = new JScrollPane();
    
    scrollPane.getViewport().add(desktopPane);

    getContentPane().add(scrollPane, gridBagConstraints);

    pack();
  }// </editor-fold>//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[])
	{
		MViewFrame mViewFrame = new MViewFrame("jMDA Type View");
		mViewFrame.run();
	}
	
	public void run()
  {
	//	UIManager.put("TitledBorder.insets", new Insets(2, 2, 2, 2));
	//	UIManager.put("InternalFrameTitlePane.font", new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	//	UIManager.put("InternalFrame.titleFont", new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	//	UIManager.put("InternalFrameTitlePane.maxFrameIconSize", new Dimension(12, 12));
	//	UIManager.put("TitledBorder.font", new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	//	UIManager.put("TitledBorder.position", TitledBorder.DEFAULT_POSITION);
	
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//			UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName());
		}
		catch (Exception e)
		{
			System.err.println(
					"failure setting system look and feel, aborting\n" + e);
			return;
		}
	
	//	try
	//	{
	//		UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName());
	//	}
	//	catch (Exception e)
	//	{
	//		System.err.println(
	//				"failure setting nimbus look and feel, aborting\n" + e);
	//		return;
	//	}
	
		EventQueue.invokeLater(new Runnable()
		{
			@Override
			public void run()
			{
				MViewFrame mViewFrame = MViewFrame.this;

//				MViewFrame mViewFrame =
//						new MViewFrame(MViewFrame.class.getSimpleName());
//						new MViewFrame("jMDA Type View");
	
				mViewFrame.setIconImage(IconProvider.getIconJMDA().getImage());
				mViewFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	
//				populateElementFactory(mViewFrame);
//				populateInheritance(mViewFrame);
//				populateAssociation(mViewFrame);
				populateTest(mViewFrame);
	
				mViewFrame.setPreferredSize(new Dimension(800, 600));
				mViewFrame.pack();
				mViewFrame.setLocationRelativeTo(null);
				mViewFrame.setVisible(true);
			}
	
			@SuppressWarnings("unused")
	    private void populateElementFactory(MViewFrame mViewFrame)
			{
				TypeElement typeElement =
						ElementFactory.getTypeElement(ElementFactory.class);
				
				TypeShape<TypeElement> typeShape =
						new TypeShape<TypeElement>(
								typeElement, displayOptionsModelContainer, null);
				
	//			typeShape.setSize(400, 100);
	
				typeShape.setLocation(100, 100);
	
				mViewFrame.getDesktopPane().add(typeShape);
	
				typeShape.setVisible(true);
			}
	
			private void populateInheritance(MViewFrame mViewFrame)
			{
				TypeElement typeElementSuper =
						ElementFactory.getTypeElement(
								ElementFactory.CPub.class);
				TypeElement typeElementSub =
						ElementFactory.getTypeElement(
								ElementFactory.CPubSub.class);
				
				TypeShape<TypeElement> typeShapeSuper =
						new TypeShape<TypeElement>(
								typeElementSuper, displayOptionsModelContainer, null);
				TypeShape<TypeElement> typeShapeSub =
						new TypeShape<TypeElement>(
								typeElementSub, displayOptionsModelContainer, null);
	
				typeShapeSuper.setSize(400, 100);
				typeShapeSub.setSize(400, 100);
	
				typeShapeSuper.setLocation(100, 100);
				typeShapeSub.setLocation(100, 300);
	
				mViewFrame.getDesktopPane().add(typeShapeSuper);
				mViewFrame.getDesktopPane().add(typeShapeSub);
	
				typeShapeSuper.setVisible(true);
				typeShapeSub.setVisible(true);
			}
	
			@SuppressWarnings("unused")
	    private void populateAssociation(MViewFrame mViewFrame)
			{
				TypeElement typeElementOwner =
						ElementFactory.getTypeElement(
								ElementFactory.CPubOwner.class);
				TypeElement typeElementOwned =
						ElementFactory.getTypeElement(
								ElementFactory.CPubOwned.class);
				
				TypeShape<TypeElement> typeShapeOwner =
						new TypeShape<TypeElement>(
								typeElementOwner, displayOptionsModelContainer, null);
				TypeShape<TypeElement> typeShapeOwned =
						new TypeShape<TypeElement>(
								typeElementOwned, displayOptionsModelContainer, null);
	
				typeShapeOwner.setSize(400, 100);
				typeShapeOwned.setSize(400, 100);
	
				typeShapeOwner.setLocation(100, 100);
				typeShapeOwned.setLocation(100, 300);
	
				mViewFrame.getDesktopPane().add(typeShapeOwner);
				mViewFrame.getDesktopPane().add(typeShapeOwned);
				typeShapeOwner.setVisible(true);
				typeShapeOwned.setVisible(true);
			}

			@SuppressWarnings("unused")
	    private void populateTest(MViewFrame mViewFrame)
			{
				TypeElement typeElement1 =
						ElementFactory.getTypeElement(
								ElementFactory.CPubOwner.class);
//								ElementFactory.IPub.class);
				TypeElement typeElement2 =
						ElementFactory.getTypeElement(
//								ElementFactory.CDef.class);
								ElementFactory.CPubOwned.class);
				
				TypeShape<TypeElement> typeShape1 =
						new TypeShape<TypeElement>(
								typeElement1, displayOptionsModelContainer, null);
				TypeShape<TypeElement> typeShape2 =
						new TypeShape<TypeElement>(
								typeElement2, displayOptionsModelContainer, null);
	
				typeShape1.setSize(400, 100);
				typeShape2.setSize(400, 100);
	
				typeShape1.setLocation(100, 100);
				typeShape2.setLocation(100, 300);
	
				mViewFrame.getDesktopPane().add(typeShape1);
				mViewFrame.getDesktopPane().add(typeShape2);
				typeShape1.setVisible(true);
				typeShape2.setVisible(true);
			}
		});
  }

	public DesktopPane getDesktopPane()
	{
		return desktopPane;
	}
	
	void setDesktopPane(DesktopPane desktopPane)
	{
		this.desktopPane = desktopPane;
	}
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private de.jmda.mview.DesktopPane desktopPane;
  // End of variables declaration//GEN-END:variables
}